namespace Management.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class CreateSomeModels : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Grades",
                c => new
                    {
                        GradeID = c.Int(nullable: false, identity: true),
                        EfficiencyRange = c.String(),
                        Power125 = c.Decimal(nullable: false, precision: 18, scale: 2),
                        Power156 = c.Decimal(nullable: false, precision: 18, scale: 2),
                        isQualified = c.Int(nullable: false),
                        Sort = c.Int(nullable: false),
                        PowerID = c.Int(nullable: false),
                        isDisabled = c.Int(nullable: false),
                        SingleCrystalPower = c.Decimal(nullable: false, precision: 18, scale: 2),
                        SingleCrystalQualified = c.Int(nullable: false),
                        SingleCrystalQualifiedP = c.Int(nullable: false),
                        CommonlyUsed = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.GradeID);
            
            CreateTable(
                "dbo.MainCheckLogs",
                c => new
                    {
                        MainCheckLogID = c.Int(nullable: false, identity: true),
                        OriDocNum = c.String(),
                        WorkshopID = c.Int(nullable: false),
                        Specification = c.String(),
                        Thickness = c.String(),
                        SiliconGrade = c.String(),
                        TestEquipment = c.String(),
                        Remark = c.String(),
                        Handler = c.String(),
                        FileName = c.String(),
                        isCheck = c.Int(nullable: false),
                        Checker = c.String(),
                        BatteryType = c.String(),
                        BatteryMaterial = c.String(),
                        BatteryAppearance = c.Int(nullable: false),
                        Factory = c.String(),
                        Created_at = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.MainCheckLogID)
                .ForeignKey("dbo.Workshops", t => t.WorkshopID, cascadeDelete: true)
                .Index(t => t.WorkshopID);
            
            CreateTable(
                "dbo.SubCheckLogs",
                c => new
                    {
                        SubCheckLogID = c.Int(nullable: false, identity: true),
                        MainCheckLogID = c.Int(nullable: false),
                        GradeID = c.Int(nullable: false),
                        GradeA = c.Int(nullable: false),
                        GradeB = c.Int(nullable: false),
                        LowLight = c.Int(nullable: false),
                        SpottedColor = c.Int(nullable: false),
                        DebrisCrack = c.Int(nullable: false),
                        TotalStorage = c.Int(nullable: false),
                        Created_at = c.DateTime(nullable: false),
                        Updated_at = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.SubCheckLogID)
                .ForeignKey("dbo.Grades", t => t.GradeID, cascadeDelete: true)
                .ForeignKey("dbo.MainCheckLogs", t => t.MainCheckLogID, cascadeDelete: true)
                .Index(t => t.MainCheckLogID)
                .Index(t => t.GradeID);
            
            AddColumn("dbo.Workshops", "Company", c => c.String());
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.SubCheckLogs", "MainCheckLogID", "dbo.MainCheckLogs");
            DropForeignKey("dbo.SubCheckLogs", "GradeID", "dbo.Grades");
            DropForeignKey("dbo.MainCheckLogs", "WorkshopID", "dbo.Workshops");
            DropIndex("dbo.SubCheckLogs", new[] { "GradeID" });
            DropIndex("dbo.SubCheckLogs", new[] { "MainCheckLogID" });
            DropIndex("dbo.MainCheckLogs", new[] { "WorkshopID" });
            DropColumn("dbo.Workshops", "Company");
            DropTable("dbo.SubCheckLogs");
            DropTable("dbo.MainCheckLogs");
            DropTable("dbo.Grades");
        }
    }
}
